﻿// Copyright © Microsoft Corporation.  All Rights Reserved.
// This code released under the terms of the 
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

namespace Microsoft.Expression.Prototyping.Mockups
{
	using System;
	using System.Windows;
	using System.Windows.Controls;
	using System.Windows.Media;

	public class ButtonWithIconMockup : Button
	{
		public Brush IconStroke
		{
			get { return (Brush)GetValue(IconStrokeProperty); }
			set { SetValue(IconStrokeProperty, value); }
		}

		public static readonly DependencyProperty IconStrokeProperty = DependencyProperty.Register("IconStroke", typeof(Brush), typeof(ButtonWithIconMockup), null);

		public Brush IconFill
		{
			get { return (Brush)GetValue(IconFillProperty); }
			set { SetValue(IconFillProperty, value); }
		}

		public static readonly DependencyProperty IconFillProperty = DependencyProperty.Register("IconFill", typeof(Brush), typeof(ButtonWithIconMockup), null);

		public Double IconSize
		{
			get { return (Double)GetValue(IconSizeProperty); }
			set { SetValue(IconSizeProperty, value); }
		}

		public static readonly DependencyProperty IconSizeProperty = DependencyProperty.Register("IconSize", typeof(Double), typeof(ButtonWithIconMockup), new PropertyMetadata(16.0, null));

		public static readonly DependencyProperty IconImageProperty = DependencyProperty.Register("IconImage", typeof(IconImage), typeof(ButtonWithIconMockup), new PropertyMetadata(IconImage.Star));

		public IconImage IconImage
		{
			get { return (IconImage)this.GetValue(IconImageProperty); }
			set { this.SetValue(IconImageProperty, value); }
		}

		public static readonly DependencyProperty IconPlacementProperty = DependencyProperty.Register("IconPlacement", typeof(IconPlacement), typeof(ButtonWithIconMockup), new PropertyMetadata(IconPlacement.Left, new PropertyChangedCallback(IconPlacementChanged)));

		public IconPlacement IconPlacement
		{
			get { return (IconPlacement)this.GetValue(IconPlacementProperty); }
			set { this.SetValue(IconPlacementProperty, value); }
		}

		private static void IconPlacementChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
		{
			((ButtonWithIconMockup)sender).OnIconPlacementChanged(e);
		}

		protected virtual void OnIconPlacementChanged(DependencyPropertyChangedEventArgs e)
		{
			VisualStateManager.GoToState(this, this.IconPlacement.ToString(), true);
		}

		public ButtonWithIconMockup()
		{
			base.DefaultStyleKey = typeof(ButtonWithIconMockup);
		}

		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			VisualStateManager.GoToState(this, Enum.GetName(typeof(IconPlacement), this.IconPlacement), false);
		}
	}
}